package com.pay.sdk.service.pay;

import java.net.InetAddress;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;

import com.google.common.base.Strings;
import com.pay.sdk.common.Configure;
import com.pay.sdk.service.IPostService;
import com.pay.sdk.util.MD5Utils;

public class ZsPrePay extends IPostService{

    private static final String SERVICE_NAME = "api.zs.prePay";
    private static final String SERVICE_VERSION = "1.0";
    private static final String SERVICE_CHARSET = "UTF-8";
    private static final String SERVICE_SIGN_TYPE = "MD5";
  

    @Override
    public String exec(Map<String, String> params){
    	String result = "";
    	try {
    		//通用参数
    		params.put("service", SERVICE_NAME);
    		params.put("version", SERVICE_VERSION);
    		params.put("sign_type", SERVICE_SIGN_TYPE);
    		params.put("charset", SERVICE_CHARSET);
    		//必填参数
    		params.put("time_start", new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()));
	        params.put("merchant_no", Configure.getMerchantNo());
	        params.put("out_trade_no", params.get("out_trade_no"));
	        params.put("total_fee", params.get("total_fee"));
	        params.put("body", params.get("body"));
			params.put("notify_url",params.get("notify_url"));
			params.put("time_expire",params.get("time_expire"));
			params.put("client_ip", InetAddress.getLocalHost().getHostAddress());
			params.put("card_type", params.get("card_type"));
			params.put("user_id", params.get("user_id"));
			params.put("mobile", params.get("mobile"));
			params.put("return_url", params.get("return_url"));
			params.put("attach", params.get("attach"));
			params.put("lat", params.get("lat"));
			params.put("lon", params.get("lon"));
			params = MD5Utils.signMap(params, SERVICE_SIGN_TYPE, Configure.getKey(), SERVICE_CHARSET);
			result = txn(Configure.isDevEnv() ? Configure.PAY_GATEWAY_DEV_API : Configure.PAY_GATEWAY_API, params);
		} catch (Exception e) {
			e.printStackTrace();
		}
    	return result;
    }
}
